﻿<UserControl 
    x:Class="TelecoSystems.Modules.Products.Views.ProductsBrowseView"    
	xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:dataForm="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"  
    xmlns:tctrls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:TelecoSystems.Modules.Products.ViewModels"
    xmlns:helpers="clr-namespace:TelecoSystems.Infrastructure.Helpers;assembly=TelecoSystems.Infrastructure"
    xmlns:cmd="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
    mc:Ignorable="d"
    d:DesignHeight="800" d:DesignWidth="1000">
    <UserControl.Resources>
        <helpers:BinaryImageConverter x:Key="BinaryImageConverter"/>
        <helpers:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <Style x:Key="SubmitButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Width="32" Height="32">
                            <Image Margin="0" Cursor="Hand" Source="/TelecoSystems.Modules.Products;component/Assets/Icons/apply.png" Width="32" Height="32"/>
                            <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0" RadiusY="3" RadiusX="3"/>
                            <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#FF6DBDD1" StrokeThickness="1"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="RejectButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Width="32" Height="32">
                            <Image Margin="0" Cursor="Hand" Source="/TelecoSystems.Modules.Products;component/Assets/Icons/cancel.png" Width="32" Height="32"/>
                            <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0" RadiusY="3" RadiusX="3"/>
                            <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#FF6DBDD1" StrokeThickness="1"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <controlsToolkit:BusyIndicator x:Name="ModuleBusyIndicator" BusyContent="{Binding BusyContent}" IsBusy="{Binding IsBusy}" Foreground="Black" DisplayAfter="0:0:0.0" FontSize="11" OverlayStyle="{StaticResource ActivityOverlayStyle}" RenderTransformOrigin="0.5,0.5">
        <Grid x:Name="LayoutRoot">
            <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <StackPanel Orientation="Horizontal">
                    <StackPanel Orientation="Vertical" MinWidth="400" MinHeight="400" d:LayoutOverrides="Height">
                        <Grid HorizontalAlignment="Stretch" Margin="0,0,0,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <RadioButton Grid.Column="0" x:Name="DataGridLayout" Content="Data grid" GroupName="ProductsLayout" />
                            <RadioButton Grid.Column="1" x:Name="ListBoxLayout" IsChecked="True" Content="List of items" GroupName="ProductsLayout" />
                            <StackPanel Grid.Column="3" Orientation="Horizontal" HorizontalAlignment="Stretch">
                                <Button x:Name="ExportToExcel" Cursor="Hand" Content="Export to Excel" cmd:Click.Command="{Binding ExportCommand}" cmd:Click.CommandParameter="Excel" Margin="0,0,10,0">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/excel.png" Width="24" Height="24" ToolTipService.ToolTip="Export to Excel" />
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button x:Name="ExportToXML" Cursor="Hand" Content="Export to XML" Margin="0,0,10,0" cmd:Click.Command="{Binding ExportCommand}" cmd:Click.CommandParameter="XML">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/xml.png" Width="24" Height="24" ToolTipService.ToolTip="Export to XML" />
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button x:Name="Print" Cursor="Hand" Content="Print" cmd:Click.Command="{Binding PrintCommand}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/fileprint.png" Width="24" Height="24" ToolTipService.ToolTip="Print" />
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </StackPanel>
                        </Grid>
                        <data:DataGrid Visibility="{Binding ElementName=DataGridLayout, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}" x:Name="ProductsData" ItemsSource="{Binding Products}" IsReadOnly="True" SelectedItem="{Binding ProductDetail, Mode=TwoWay}" Background="#FF121212" GridLinesVisibility="Horizontal" BorderBrush="#FF434546" />
                        <ListBox x:Name="ListBoxProducts" Visibility="{Binding ElementName=ListBoxLayout, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}" DataContext="{Binding ElementName=ProductsData}" ItemsSource="{Binding Path=ItemsSource, Mode=OneWay}" SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" Background="#FF121212" BorderBrush="#FF434546">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Height="50" Margin="10,5,10,5">
                                        <TextBlock Margin="60,3,82,0" Text="{Binding Name, Mode=OneWay}" TextWrapping="Wrap" Height="20" VerticalAlignment="Top"/>
                                        <TextBlock Margin="61,23,8,0" FontSize="12" Text="{Binding Description, Mode=OneWay}" TextWrapping="Wrap"/>
                                        <Image HorizontalAlignment="Left" Width="48" Height="48" Source="{Binding Image, Converter={StaticResource BinaryImageConverter}, Mode=OneWay}" Stretch="Fill"/>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <ListBox.Effect>
                                <DropShadowEffect />
                            </ListBox.Effect>
                        </ListBox>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                            <data:DataPager PageSize="{Binding PageSize}" HorizontalAlignment="Stretch" Source="{Binding Products}" PageIndex="{Binding PageIndex}" />
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Margin="20,0,0,0">
                        <TextBlock Text="Detail" HorizontalAlignment="Left" FontSize="14" Margin="0,0,10,0" Foreground="#FFEEEEEE" />
                        <dataForm:DataForm MinHeight="150" DataContext="{Binding ElementName=ProductsData}" ItemsSource="{Binding Path=ItemsSource, Mode=TwoWay}" Header="Form" HeaderVisibility="Visible" AutoEdit="False" AutoCommit="False" Background="#FFB2B2B2" Width="300">
                            <!--CurrentItem="{Binding Path=SelectedItem, Mode=TwoWay}"-->
                            <dataForm:DataForm.Effect>
                                <DropShadowEffect/>
                            </dataForm:DataForm.Effect>
                        </dataForm:DataForm>
                        <StackPanel Orientation="Horizontal" Margin="0,10,0,0" Drop="StackPanel_Drop" AllowDrop="True" DragEnter="StackPanel_DragEnter" DragLeave="StackPanel_DragLeave" >
                            <Border Margin="0,0,20,0" Padding="3">
                                <Image x:Name="ProductImage" Tag="{Binding ElementName=ProductsData, Path=SelectedItem.Image, Mode=TwoWay}" Source="{Binding Tag, Converter={StaticResource BinaryImageConverter}, ElementName=ProductImage, Mode=OneWay}" />
                            </Border>
                            <Button x:Name="ProductImageLoadButton" Content="Load image" Click="Button_Click" Height="22" Width="100" />
                        </StackPanel>
                        <StackPanel Orientation="Vertical" Visibility="{Binding ContextHasChanges}">
                            <StackPanel Orientation="Horizontal" Margin="0,15,0,0">
                                <TextBlock Text="Apply changes" Margin="0,0,20,0" Style="{StaticResource ContentTextStyle}" VerticalAlignment="Center" />
                                <Button cmd:Click.Command="{Binding SubmitChangesCommand}" Content="Apply" Width="Auto" Height="32" Margin="0" HorizontalAlignment="Left" Padding="6,2,36,2" />
                                <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/apply.png" Width="24" Height="24" Margin="-34,0,20,0" IsHitTestVisible="False" />
                                <Button cmd:Click.Command="{Binding RejectChangesCommand}" Content="Reject" Width="Auto" Height="32" Margin="0" HorizontalAlignment="Right" Padding="6,2,36,2" />
                                <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/cancel.png" Width="24" Height="24" Margin="-34,0,0,0" IsHitTestVisible="False" />
                            </StackPanel>
                            <TextBlock FontSize="10.667" Text="Changed records are marked with asterisk(*)." Style="{StaticResource ContentTextStyle}" Margin="0,5,0,0"/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Margin="20,0,0,0" MinWidth="220">
                        <!--<data:DataGrid x:Name="VariantsDataGrid" IsReadOnly="True" ItemsSource="{Binding Path=ProductDetail.Variants}" SelectedItem="{Binding Path=VariantDetail, Mode=TwoWay}" Background="#FF121212" BorderBrush="#FF434546" />-->
                        <StackPanel Orientation="Horizontal" Height="24" HorizontalAlignment="Stretch" Margin="0,0,10,0">
                            <TextBlock Text="Variants" HorizontalAlignment="Left" FontSize="14" Margin="0,0,60,0" Foreground="#FFEEEEEE" />
                            <Button HorizontalAlignment="Right" cmd:Click.Command="{Binding AddVariantCommand}" Cursor="Hand">
                                <Button.Template>
                                    <ControlTemplate>
                                        <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/add.png" Width="24" Height="24" />
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                            <Button HorizontalAlignment="Right" cmd:Click.Command="{Binding EditVariantCommand}" Cursor="Hand">
                                <Button.Template>
                                    <ControlTemplate>
                                        <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/edit.png" Width="24" Height="24" />
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                            <Button HorizontalAlignment="Right" cmd:Click.Command="{Binding DeleteVariantCommand}" Cursor="Hand">
                                <Button.Template>
                                    <ControlTemplate>
                                        <Image Source="/TelecoSystems.Modules.Products;component/Assets/Icons/delete.png" Width="24" Height="24" />
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                        </StackPanel>

                        <ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" x:Name="VariantsListBox" MinHeight="60" ItemsSource="{Binding Path=ProductDetail.Variants, Mode=OneWay}" SelectedItem="{Binding Path=VariantDetail, Mode=TwoWay}" Background="#FF121212" BorderBrush="#FF434546">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Width="200" Height="65" Margin="0">
                                        <TextBlock FontSize="16" Text="{Binding Name, Mode=OneWay}" TextWrapping="Wrap" Height="18" Margin="10,4,10,0" VerticalAlignment="Top" d:LayoutOverrides="Height"/>
                                        <CheckBox HorizontalAlignment="Right" Margin="0,4,10,0" Content=" in sale" IsChecked="{Binding IsInSale, Mode=OneWay}" Height="15" VerticalAlignment="Top" Foreground="Black" IsEnabled="False"/>
                                        <TextBlock HorizontalAlignment="Left" Text="{Binding Description, Mode=OneWay}" TextWrapping="Wrap" Width="200" Margin="10,26,0,0" FontSize="10.667"/>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <ListBox.Effect>
                                <DropShadowEffect />
                            </ListBox.Effect>
                        </ListBox>

                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </controlsToolkit:BusyIndicator>
</UserControl>
